package com.zlz.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zlz.server.annotation.OperateLog;
import com.zlz.server.enums.OprLevel;
import com.zlz.server.pojo.Employee;
import com.zlz.server.pojo.RespBean;
import com.zlz.server.reqparam.EmpSalaryUpdateParam;
import com.zlz.server.service.IEmployeeService;
import com.zlz.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: zlz
 * @date: 2021/3/20 22:38
 * @description:
 * @since: JDK1.8
 */
@RestController
@RequestMapping("/salary/sobcfg")
public class SalarySobCfgController {
    @Resource
    private ISalaryService iSalaryService;

    @Resource
    private IEmployeeService iEmployeeService;

    @ApiOperation("获取所有工资账套")
    @GetMapping("/salaries")
    public RespBean getAllSalaries() {
        return RespBean.success(iSalaryService.list());
    }

    @ApiOperation("获取所有员工工资账套")
    @GetMapping("/")
    public RespBean getEmpsWithSalary(@RequestParam(defaultValue = "1") Integer curPage,
                                      @RequestParam(defaultValue = "10") Integer size) {
        return RespBean.success(iEmployeeService.getEmpsWithSalary(curPage, size));
    }

    @ApiOperation("更新员工资账套")
    @PutMapping("/")
    @OperateLog(moduleName = "员工工资", operationName = "更新员工资账套", level = OprLevel.NORMAL)
    public RespBean updateEmpSalary(@RequestBody EmpSalaryUpdateParam param) {
        iEmployeeService.update(new UpdateWrapper<Employee>().set("salary_id", param.getSid())
                .eq("id", param.getEid()));
        return RespBean.success();
    }
}
